﻿Imports DTO
Imports System.Data.OleDb

Public Class LoaiNguoiDungDAO

    Public Function LayDanhSach() As List(Of LoaiNguoiDungDTO)
        Dim strSQL = "SELECT * FROM LOAINGUOIDUNG"
        Dim conn As OleDbConnection = DataProvider.ConnectDB()
        Dim cmd As New OleDbCommand(strSQL, conn)
        Dim reader As OleDbDataReader = cmd.ExecuteReader()

        Dim ds As New List(Of LoaiNguoiDungDTO)
        While (reader.Read())
            Dim lndDTO As New LoaiNguoiDungDTO()
            lndDTO.MaLoaiNguoiDung = reader("MaLoaiNguoiDung")
            lndDTO.TenLoaiNguoiDung = reader("TenLoaiNguoiDung")
            lndDTO.DanhSach = reader("DanhSach")
            lndDTO.PhatSinh = reader("PhatSinh")
            lndDTO.BaoBieu = reader("BaoBieu")
            lndDTO.BangDiem = reader("BangDiem")
            lndDTO.TraCuu = reader("TraCuu")
            lndDTO.QuanTri = reader("QuanTri")
            ds.Add(lndDTO)
        End While
        conn.Close()
        Return ds
    End Function

    Public Function CapNhatQuyenSuDung(ByVal lndDTO As LoaiNguoiDungDTO) As Integer
        Dim strSQL = " UPDATE LOAINGUOIDUNG"
        strSQL = strSQL + " SET DanhSach=" + lndDTO.DanhSach + ", PhatSinh=" + lndDTO.PhatSinh + ", BaoBieu=" + lndDTO.BaoBieu + ", TraCuu=" + lndDTO.TraCuu + ", BangDiem=" + lndDTO.BangDiem + ", QuanTri=" + lndDTO.QuanTri
        strSQL = strSQL + " WHERE MaLoaiNguoiDung=" + lndDTO.MaLoaiNguoiDung.ToString()
        Dim conn As OleDbConnection = DataProvider.ConnectDB
        Dim cmd As New OleDbCommand(strSQL, conn)
        Dim r As Integer = cmd.ExecuteNonQuery
        conn.Close()

        If r = 1 Then
            Return 1
        Else
            Return 0
        End If

    End Function

End Class

